<?php

namespace App\Services\Address;

use App\Services\Address\Address\AddressLogic;

/**
 * 地址服务层
 * Class ApiArticle
 * @package App\Services\Address
 */
class Address
{
    // 添加新地区
    public function createAddress($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,["pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""]);
        ValidateAddress::checkValidate($data, ['pid', 'name', 'py_name', 'zipcode', 'special']);

        return (new AddressLogic())->createAddress($data);
    }

    // 编辑地区信息
    public function editAddress($data): array
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }

        $data = init_array($data,["id"=>0,"pid"=>0, "name"=>"", "py_name"=>"", "zipcode"=>"", "type"=>3, "special"=>0, "order"=>""]);
        ValidateAddress::checkValidate($data, ['id', 'pid', 'name','py_name', 'zipcode', 'special']);

        return (new AddressLogic())->editAddress($data);
    }

    // 全部地区列表获取
    public function addressList()
    {
        return (new AddressLogic())->addressList();
    }

    // 某一类地区列表获取
    public function someAddressList($data)
    {
        if (empty($data)) {
            return null_data($data,"参数不能为空！");
        }
        $data = init_array($data,['pid'=>'']);
        $validate = ['pid' => true];
        ValidateAddress::checkValidate($data, ['pid'],true,$validate);

        return (new AddressLogic())->someAddressList($data);
    }
}